var map;
var manager;
function load() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("maphost"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        showAddress(map, "Bangalore");
    }
}

function showAddress(map, address) {
    search(address);
}

// this function will be called by our JSON callback
// the parameter jData will contain an array with geonames objects
function getLocation(jData) {
    document.getElementById('dump').innerHTML += "Call back happens!<br/>";
    if (jData == null) {
        // There was a problem parsing search results
        document.getElementById('dump').innerHTML += "Null return!<br/>";
        return;
    }
    //    var html='';
    //    for (i = 0; i < geonames.length; i++) {
    //        var name = geonames[i];
    //        // we create a simple html list with the geonames objects
    //        // the link will call the center() javascript method with lat/lng as parameter
    //        html = html + '<a href="javascript:center(' + name.lat + ',' + name.lng + ');">' + name.name + '</a><br>';
    //    }
    //    document.getElementById('dump').innerHTML += html;
    points = jData.geonames;
    var point = points[0];
    document.getElementById('dump').innerHTML += "Got coords: " + point.lat + ", " + point.lng + " !<br/>";
    var ll = new GLatLng(point.lat, point.lng);

    map.setCenter(ll, 13);
    map.setMapType(G_HYBRID_MAP);
    map.addOverlay(new GMarker(ll));
}

// calls the geonames JSON webservice with the search term
function search(searchText) {
    request = 'http://ws.geonames.org/searchJSON?q=' + encodeURIComponent(searchText) + '&maxRows=10&callback=getLocation';
    document.getElementById('dump').innerHTML += "Sending request!<br/>";
    // Create a new script object
    // (implementation of this class is in /export/jsr_class.js)
    aObj = new JSONscriptRequest(request);
    // Build the script tag
    aObj.buildScriptTag();
    // Execute (add) the script tag
    aObj.addScriptTag();
}

function getXml() {
    var request = GXmlHttp.create();
    request.open("GET", "http://upcoming.org/services/rest/?api_key=6acd31dc0a&method=event.search&search_text=bangalore", "true");
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            alert(xmlDoc);
        }

    }
}